package com.film.web.controller.cinema;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;


import com.film.common.core.domain.entity.SysDept;
import com.film.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.film.common.annotation.Log;
import com.film.common.core.controller.BaseController;
import com.film.common.core.domain.AjaxResult;
import com.film.common.enums.BusinessType;
import com.film.cinema.domain.Emp;
import com.film.cinema.service.IEmpService;
import com.film.common.utils.poi.ExcelUtil;
import com.film.common.core.page.TableDataInfo;

/**
 * 员工管理Controller
 * 
 * *@author fy
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/cinema/emp")
public class EmpController extends BaseController
{
    @Autowired
    private IEmpService empService;
    @Autowired
    private ISysDeptService deptService;
    /**
     * 查询员工管理列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:list')")
    @GetMapping("/list")
    public TableDataInfo list(Emp emp)
    {
        startPage();
        List<Emp> list = empService.selectEmpList(emp);
       return getDataTable(list);
    }
    /**
     * 导出员工管理列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:export')")
    @Log(title = "员工管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Emp emp)
    {
        List<Emp> list = empService.selectEmpList(emp);
        ExcelUtil<Emp> util = new ExcelUtil<Emp>(Emp.class);
        util.exportExcel(response, list, "员工管理数据");
    }

    /**
     * 获取员工管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:query')")
    @GetMapping(value = "/{empId}")
    public AjaxResult getInfo(@PathVariable("empId") Long empId)
    {
        return success(empService.selectEmpByEmpId(empId));
    }

    /**
     * 新增员工管理
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:add')")
    @Log(title = "员工管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Emp emp)
    {
        return toAjax(empService.insertEmp(emp));
    }

    /**
     * 修改员工管理
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:edit')")
    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Emp emp)
    {
        return toAjax(empService.updateEmp(emp));
    }

    /**
     * 删除员工管理
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:remove')")
    @Log(title = "员工管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{empIds}")
    public AjaxResult remove(@PathVariable Long[] empIds)
    {
        return toAjax(empService.deleteEmpByEmpIds(empIds));
    }
    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/deptTree")
    public AjaxResult deptTree(SysDept dept)
    {
        return success(deptService.selectDeptTreeList(dept));
    }
    /**
     * 统计每个部门员工的人数
     */
    @PreAuthorize("@ss.hasPermi('cinema:emp:deptEmpCount')")
    @GetMapping("/deptEmpCount")
    public AjaxResult deptEmpCount() {
        List <Map<String, Emp> >deptEmpCount = empService.countEmpsByDept();
        return AjaxResult.success(deptEmpCount);
    }

}
